package MaxMaze;
import static MaxMaze.MMkonstanten.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public class MazeDrawPanel extends JPanel
 
{
  // Anfang Attribute
  private MazeArray myMazeRef;
  // Ende Attribute
  
  public MazeDrawPanel (LayoutManager layout, boolean isDoubleBuffered, MazeArray myMaze)
  {
    super(layout, isDoubleBuffered);
    myMazeRef = myMaze;
  }
  // Anfang Methoden
  
  @Override                           
  protected void paintComponent( Graphics g )
  {
    // Zellennummer in x- bzw. y-Richtung
    int x;
    int y;
    
    Graphics2D g2 = (Graphics2D) g;
    
    super.paintComponent( g2 );
    
    g2.setStroke(new BasicStroke(4, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL));
    
    g2.setColor(Color.BLACK);
    
    for (y= 0; y< ANZY; y++) 
    {
      for (x= 0; x< ANZX; x++)
      {
        if (myMazeRef.getZelle(y, x, OBEN) == ZU) 
        {
          g2.drawLine( x*ZBR + X0, y*ZHOE + Y0, x*ZBR + X1, y*ZHOE + Y0); // obere Wand
        } 
        if (myMazeRef.getZelle(y, x, RECHTS) == ZU) 
        {
          g2.drawLine( x*ZBR + X1, y*ZHOE + Y0, x*ZBR + X1, y*ZHOE + Y1); // rechte Wand
        }
        if (myMazeRef.getZelle(y, x, UNTEN) == ZU) 
        {
          g2.drawLine( x*ZBR + X1, y*ZHOE + Y1, x*ZBR + X0, y*ZHOE + Y1); // untere Wand
        }
        if (myMazeRef.getZelle(y, x, LINKS) == ZU) 
        {
          g2.drawLine( x*ZBR + X0, y*ZHOE + Y1, x*ZBR + X0, y*ZHOE + Y0); // linke Wand
        }
      } 
    } 
    
    
    if ((myMazeRef.getSpielerPosX() == ANZX-1) && (myMazeRef.getSpielerPosY() == ANZY-1)) 
    {
      g2.setColor(Color.GREEN);
    } 
    else
    {
      g2.setColor(Color.RED);
    }
    
    g2.fillRect(SP_OFFSET + ZBR * myMazeRef.getSpielerPosX(), SP_OFFSET + ZHOE * myMazeRef.getSpielerPosY(), SPBR, SPHOE);
  }
  
} 
  
  
  
  

  
   
    
                               
    
    
  
  
  
  

